<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategy.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/css/dialog.css">
		<script src="/js/plugins/dialog2/js/dialog.min.js"></script>


		<script>
			$(function () {
			    //获得地区标签的操作
                $.get("/regions/1",function (data) {
                    //console.log(data);
                    var html = '';
                    var content = '';
                    $.each(data,function (index,item) {
                        html+= '<li class="nav-item">'+
						'<a data-id="'+item.id+'" class="nav-link" id="pills-'+item.id+'-tab" data-toggle="pill" href="#pills-'+item.id+'">'
						+item.name+'</a>'+'</li>';

						content+='<div class="tab-pane fade" id="pills-'+item.id+'"></div>'
                    });
                    $("#pills-tab").append(html);
                    $("#pills-tabContent").append(content);
                });
                var regionId
                    //动态的绑定点击事件,on前面的是一个范围
				// on第一个参数是什么事件,这里是点击事件,第二个是选择器,最后一个是函数,要做什么
					$("#pills-tab").on("click",".nav-link",function () {
					    
					   regionId = $(this).data("id");
					    if(regionId){
                            $.get("/regions/"+regionId+"/strategies",function (data) {
                                $("#pills-"+regionId).html(data);
                            },"html");
						}
                    });



				//全部攻略翻页
                var currentPage = 2;  //定义一个临时当前页变量
                var dataList = [];  //防止jrender丢失上一页数据设置
                var totalPage=2;  //总页数至少为1
                //分页抽取出来的方法
                function query() {
                    //查询第一个游记,传入参数pageSize为分页的条数
                    $.get("/regions/"+regionId+"/strategies", {pageSize: 4,currentPage:currentPage}, function (data) {

                        var html = '';
						$.each(data.list,function(index,item){
                            html +='<div class="col-6 mb">'+
                                '<a href="../strategyCatalogs.html?id='+item.id+'">'+
                                '<img class="float-left " src="'+item.coverUrl+'">'+
                                '<div class="classify-text">'+
                                '<span>'+item.subTitle+'</span>'+
                                '<p>0人收藏</p>'+
                                '</div>' +'</a>'+
                                '</div>';
						});
						$(".classfy").append(html);
                        currentPage += 1;
                        totalPage = data.pages;
                    });
                }



                //屏幕滚动时间
                $(window).scroll(function () {
                    if ($(window).height() + $(window).scrollTop() +1 >= $(document).height()) {
                        if (currentPage <= totalPage) {
                            query();
                        } else {
                            $(document).dialog({
                                type: 'notice',
                                infoText: '人家可是有底线的哦!',
                                autoClose: 2500,
                                position: 'bottom'  // center: 居中; bottom: 底部
                            });
                        }
                    }
                });






				//获取推荐攻略
                $.get("/travels/travelCommends",{type:3},function (data) {
                    //console.log(data);
					
                    $("#pills-top").renderValues(data,{
                        setHref:function (item,value) {
							var href = $(item).attr("href")+value;
							$(item).attr("href",href);
                        }
					});
                    //这个是选中第一个添加active属性
                    $(".carousel-item:first").addClass("active");
                });


				//获得大攻略里面状态为推荐的操作,当季推荐
                $.get("/strategies",{state:2,pageSize:0},function (data) {
                    console.log(data);
                    $(".strategyCommend").renderValues(data,{
                        setHref:function (item,value) {
                            var href = $(item).attr("href")+value;
                            $(item).attr("href",href);
                        }
					});
                });
            });

		</script>

	</head>

	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input class="form-control searchBtn" placeholder="找攻略">
				</div>
			</div>
		</div>
	</div>

	<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
		<li class="nav-item">
			<a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
				<span style="font-weight: bold;">推荐</span>
			</a>
		</li>
	</ul>

	<!--大攻略中为推荐的-->
	<div class="tab-content" id="pills-tabContent">
		<div class="tab-pane fade active show" id="pills-top">


			<div class="container commend" render-loop="list">
				<div class="carousel-item">
					<a href="/travelContent.html?id=" render-fun="setHref" render-key="list.travelId">
						<img render-src="list.commendCoverUrl">
						<p render-html="list.commendTitle"></p>
					</a>
				</div>
			</div>

			<div class="container strategyCommend">
				<h6>当季推荐</h6>
				<div class="row hot" render-loop="list">

					<div class="col-4">
						<a render-href="strategyCatalogs.html?id=" render-fun="setHref" render-key="list.id">
							<img render-src="list.coverUrl">
							<p render-html="list.title"></p>
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>
	</body>

</html>